/**
 *简介更新state的多个方法的对象
 */
import {RECEIVE_ADDRESS,RECEIVE_CATEGORYS,RECEIVE_SHOPS} from './mutation-types'
import {reqAddress,reqFoodCategorys,reqShops} from '../api'
export default {
    //异步获取地址
    async getAddress({commit,state}){
    //发送异步ajax请求
    const geogash = state.latitude+','+state.longitude
    const result= await reqAddress(geogash)
      if(result.code===0){
        const address = result.data
          //提交到mutation
        commit(RECEIVE_ADDRESS,{address})
      }
  },
    //异步获取食品分类
  async getCategorys({commit}){
    //发送异步ajax请求
    const result= await reqFoodCategorys()
    if(result.code===0){
      const categorys = result.data
      //提交到mutation
      commit(RECEIVE_CATEGORYS,{categorys})
    }
  },
    //异步获取商家列表
  async getShops({commit,state}){
    //发送异步ajax请求
    const{longitude,latitude}=state
    const result= await reqShops(longitude,latitude)
    if(result.code===0){
      const shops = result.data
      //提交到mutation
      commit(RECEIVE_SHOPS,{shops})
    }
  },
}
